package com.ztom.v2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ZhangTao
 */
public class Code02GroupAnagrams {

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] charArray = str.toCharArray();
            Arrays.sort(charArray);
            map.computeIfAbsent(String.valueOf(charArray), k -> new ArrayList<>())
                    .add(str);
        }
        return new ArrayList<>(map.values());
    }
}
